<?php

/**
 * This is the model class for table "portfolioname".
 *
 * The followings are the available columns in table 'portfolioname':
 * @property integer $id
 * @property string $name
 * @property integer $accountID
 * @property string $description
 *
 * The followings are the available model relations:
 * @property Dividend[] $dividends
 * @property Portfolio[] $portfolios
 * @property Account $account
 */
class Portfolioname extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Portfolioname the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'portfolioname';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, accountID', 'required'),
			array('accountID', 'numerical', 'integerOnly'=>true),
			array('accountID, brokerage_fee, dividend_withholding_tax, capital_gain_tax_rate, yield_on_government_bonds', 'numerical'),
			array('name', 'length', 'max'=>50),
			array('description', 'length', 'max'=>200),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, accountID, description, brokerage_fee, dividend_withholding_tax, capital_gain_tax_rate, yield_on_government_bonds', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'dividends' => array(self::HAS_MANY, 'Dividend', 'portfolionameID'),
			'portfolios' => array(self::HAS_MANY, 'Portfolio', 'portfolionameID'),
			'account' => array(self::BELONGS_TO, 'Account', 'accountID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'accountID' => 'Account',
			'description' => 'Description',
			'brokerage_fee' => 'Brokerage Fee',
			'dividend_withholding_tax' => 'Dividend Withholding Tax',
			'capital_gain_tax_rate' => 'Capital Gain Tax Rate',
			'yield_on_government_bonds' => 'Yield On Government Bonds',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('accountID',$this->accountID);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('brokerage_fee',$this->brokerage_fee,true);
		$criteria->compare('dividend_withholding_tax',$this->dividend_withholding_tax,true);
		$criteria->compare('capital_gain_tax_rate',$this->capital_gain_tax_rate,true);
		$criteria->compare('yield_on_government_bonds',$this->yield_on_government_bonds,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}